package com.woniuxy.threeprojcet.end_water_project_admin.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.woniuxy.threeprojcet.end_water_project_admin.domain.Repair;
import com.woniuxy.threeprojcet.end_water_project_admin.domain.User;
import com.woniuxy.threeprojcet.end_water_project_admin.domain.form.RePairForm;
import com.woniuxy.threeprojcet.end_water_project_admin.service.impl.RepairServiceImpl;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 * 维修表 前端控制器
 * </p>
 *
 * @author Lucas
 * @since 2021-08-26
 */
@RestController
@CrossOrigin("*")
@RequestMapping("/admin")
@Slf4j
public class RepairController {
    @Resource
    private RepairServiceImpl repairService;

    @GetMapping("getRepair")
    public IPage getRepair(@RequestParam(name = "pageSize", defaultValue = "3") int pageSize,
                          @RequestParam(name = "current", defaultValue = "1") int current) {


        IPage page = new Page(current, pageSize);

//        List<Repair> repair = repairService.getRepair(page);
        IPage repair = repairService.getRepair(page);
//        ArrayList newRepair = new ArrayList();
//        for(int i = 0; i < repair.getSize(); i++) {
//            User userAddress = findUserAddress(repair.get(i).getWaterMeterId());
//            String address = userAddress.getAddress();
//            RePairForm rePairForm = new RePairForm();
//            BeanUtils.copyProperties(repair.get(i), rePairForm);
//            rePairForm.setAddress(address);
//            newRepair.add(rePairForm);
//        }

        return repair;
    }
    @PostMapping ("updateState")
    public boolean updateState(@RequestBody Repair repairId) {
        log.info("repairId:{}",repairId);
        boolean b = repairService.updateState(repairId.getRepairId());
        return b;
    }


    //获得用户地址
    public User findUserAddress(int waterMeterId){


        User userAddress = repairService.findUserAddress(waterMeterId);
        return userAddress;

    }


}

